package top.mask.mq.direct;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import top.mask.mq.utils.RabbitMQUtil;

@Slf4j
public class ReceiveLogsDirect02 {

    public static final String EXCHANGE_NAME = "direct_logs";

    @SneakyThrows
    public static void main(String[] args) {
        Channel channel = RabbitMQUtil.getChannel();
        //声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        //声明一个队列
        channel.queueDeclare("disk",false,false,false,null);
        channel.queueBind("disk",EXCHANGE_NAME,"error");

        DeliverCallback deliverCallback = (consumerTag, message) ->
                log.info("ReceiveLogsDirect02日志打印接收到的消息{}",new String(message.getBody(),"UTF-8"));

        CancelCallback cancelCallback = consumerTag ->
                log.info("消息者取消消接口回调逻辑{[]}",consumerTag);

        channel.basicConsume("disk",true,deliverCallback,cancelCallback);

    }
}
